#include "AnalysisMsg.h"

AnalysisMsg::AnalysisMsg()
{

}

void AnalysisMsg::Analysis(list<string> &dataList)
{
    if( !dataList.empty() )
    {
        list<string>::iterator it;
        for( it = dataList.begin(); it != dataList.end(); ++it )
        {
            //qDebug() << it->c_str();
            BackMessageData msgData = m_dealMsg.DealMsg((unsigned char*)it->c_str(), it->length() );
            if( msgData.operaterSuccess != COMMAND_SUCCESS ){
                continue;
            }
            switch (msgData.type) {
            case 0x6A:
                 emit Signal_RfLinkProfile(msgData.msgStr[0]);
                //break;
           // case 0x71:
                //ProcessSetUartBaudrate(msg, nLen, msgData);
                //break;
            case 0x72:
                emit Signal_ShowFirewareVersion((char*)msgData.msgStr, 8);
                break;
//            case 0x73:
//                ProcessSetReadAddress(msg, nLen, msgData);
//                break;
//            case 0x74:
//                ProcessSetWorkAntenna(msg, nLen, msgData);
//                break;
            case 0x75:
            {
                emit Signal_ReadWorkAnt(msgData.msgStr[0]);
                break;
            }
//            case 0x76:
//                break;
            case 0x77:

                emit Signal_ShowOutputPower( (int)msgData.msgStr[0] );
                break;
//            case 0x78:
//                ProcessSetFrequencyRegion(msg, nLen, msgData);
//                break;
            case 0x79:{
                FreqRegionData data;
                memset(&data, 0, sizeof(FreqRegionData));
                memcpy(&data, msgData.msgStr, msgData.msgLen);
                if( data.type == 0 )
                {
                    emit Signal_FreqRegion(data.defaultFreq);
                }
                else{
                    emit Signal_FreqRegionCustom(data.customFreq, data.customFreq.nstartFreq);
                }
                break;
            }
//            case 0x7A:
//                ProcessSetBeeperMode(msg, nLen, msgData);
//                break;
            case 0x7B:
                emit Signal_ShowReaderTemp((char*)msgData.msgStr, msgData.msgLen );
                break;
            //case 0x7C:
               // ProcessSetDrmMode(msg, nLen, msgData);
               // break;
            case 0x7D: {

                emit Signal_DrmModeGet( msgData.msgStr[0] );
                break;
            }
            case 0x7E:  //回波损耗
            {

                emit Signal_ReturnLoss( msgData.msgStr[0]);
                break;
            }
            case 0x60:{
                unsigned char* p = (unsigned char*)msgData.msgStr;
                emit Signal_ReadGPIO(p[0], p[1]);
                break;
            }
           // case 0x61:
            //    ProcessWriteGpioValue(msg, nLen, msgData);
              //  break;
            //case 0x62:
            //    ProcessSetAntDetector(msg, nLen, msgData);
            //    break;
            case 0x63:
            {
                unsigned char* p = (unsigned char*)msgData.msgStr;
                emit Signal_GetAntDetector(p[0]);
                break;
            }
          //  case 0x67:
            //    ProcessSetReaderIdentifier(msg, nLen, msgData);
           //     break;
            case 0x68:
                emit Signal_ShowReaderIdentifier(QString((const char*)msgData.msgStr));
                break;

           // case 0x80:
             //   ProcessInventory(msg, nLen, msgData);
              //  break;
            case 0x81:
            {
                TagReadBack tag;
                memcpy(&tag, (char*)msgData.msgStr, msgData.msgLen );
                emit Signal_ShowReadTagData(tag);
                break;
            }
            case 0x82:
            {
                TagReadBack tag;
                memcpy(&tag, (char*)msgData.msgStr, msgData.msgLen );
                emit Signal_ShowReadTagData(tag);
                break;
            }
            case 0x83:
            {
                TagReadBack tag;
                memcpy(&tag, (char*)msgData.msgStr, msgData.msgLen );
                emit Signal_ShowReadTagData(tag);
                break;
            }
            case 0x84:
            {
                TagReadBack tag;
                memcpy(&tag, (char*)msgData.msgStr, msgData.msgLen );
                emit Signal_ShowReadTagData(tag);
                break;
            }
           // case 0x85:
             //   ProcessSetAccessEpcMatch(msg, nLen, msgData);
             //   break;
            case 0x86:
                emit Signal_GetAccessEpc( msgData.msgStr, msgData.msgLen );
                break;

            case 0x89:
            {
                RealInventoryData data;
                memset(&data, 0, sizeof(RealInventoryData));
                memcpy(&data, msgData.msgStr, msgData.msgLen );
                if( data.dataType == 0 )
                {
                    emit Signal_ShowInventoryData(data.countData);
                }
                else
                {
                    emit Signal_ShowEpcBuffer(data.epcData);
                }
                break;
            }
            case 0x8B:
            {
                RealInventoryData data;
                memset(&data, 0, sizeof(RealInventoryData));
                memcpy(&data, msgData.msgStr, msgData.msgLen );
                if( data.dataType == 0 )
                {
                    emit Signal_ShowInventoryData(data.countData);
                }
                else if( data.dataType == 1 )
                {
                    emit Signal_ShowEpcBuffer(data.epcData);
                }
                break;
            }
            case 0x8A:
            {
                FastInventoryData data;
                memset(&data, 0, sizeof(FastInventoryData));
                memcpy(&data, msgData.msgStr, msgData.msgLen );
                if( data.dataType == 0 )
                {
                    emit Signal_ShowFastInventoryData(data.labelTime, data.command);
                }
                else if( data.dataType == 1 )
                {
                    emit Signal_ShowFastEpcBuffer(data.epcData);
                }
                break;
            }
            case 0x8D:
                //ProcessSetMonzaStatus(msg, nLen, msgData);
                break;
            case 0x8E:
              //  ProcessGetMonzaStatus(msg, nLen, msgData);
                break;
            case 0x90:
              //  ProcessGetInventoryBuffer(msg, nLen, msgData);
                break;
            case 0x91:
              //  ProcessGetAndResetInventoryBuffer(msg, nLen, msgData);
                break;
            case 0x92:
              //  ProcessGetInventoryBufferTagCount(msg, nLen, msgData);
                break;
            case 0x93:
              //  ProcessResetInventoryBuffer(msg, nLen, msgData);
                break;
            case 0xb0:
              //  ProcessInventoryISO18000(msg, nLen, msgData);
                break;
            case 0xb1:
              //  ProcessReadTagISO18000(msg, nLen, msgData);
                break;
            case 0xb2:
              //  ProcessWriteTagISO18000(msg, nLen, msgData);
                break;
            case 0xb3:
             //   ProcessLockTagISO18000(msg, nLen, msgData);
                break;
            case 0xb4:
             //   ProcessQueryISO18000(msg, nLen, msgData);
                break;
            default:
                break;
            }
        }
        dataList.clear();
    }

}
